﻿using System.Reflection;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject;
using Ninject.Web.Mvc;
using WroxBlog.BindingModules;

namespace WroxBlog
{
    public class MvcApplication : NinjectHttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Category",
                "category/{name}",
                new
                {
                    controller = "Category",
                    action = "CategoryIndex",
                    name = ""
                });

            routes.MapRoute(
                "Post",
                "post/{id}",
                new
                {
                    controller = "Post",
                    action = "IndividualPost",
                    id = ""
                });

            routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = "" }
            );
        }

        protected override IKernel CreateKernel()
        {
            IKernel kernel = new StandardKernel(new RepositoriesModule());
            return kernel;
        }

        protected override void OnApplicationStarted()
        {
            RegisterRoutes(RouteTable.Routes);
            RegisterAllControllersIn(Assembly.GetExecutingAssembly());
        }
    }
}